﻿String.prototype.trimSpace=function(){
	return this.replace(/\s+|　/g,"");
}
if(!window.searchEngine)
{
    var searchEngine=window.searchEngine={
        news:{
            baidu:"'http://news.baidu.com/ns?word='+document.getElementById('kw').value",
            google:"'http://www.google.com.hk/search?q='+encodeURIComponent(document.getElementById('kw').value)"
        }
    };
    
}

function openWindow(openUrl)
{
	var obj=window.open(openUrl);
}

function search(){
    var objKey=document.getElementById('kw');
    var keyword=objKey.value;
	if(keyword=='请输入搜索关键字...'||keyword.trimSpace()=='')
	{		
		alert('请输入关键字！');
		objKey.value='';
		objKey.focus();
		return false;
	}
	var objFlag=document.getElementById('flag');
	var searchUrl='/search/search'+objFlag.value+'.html?url=';	
	
	var objUrl=document.getElementById('s');
	var tagsUrl=objUrl.getElementsByTagName('label');
    var isChecked=false;
	for(var i=0;i<tagsUrl.length;i++)
	{
	    if(tagsUrl[i].className=='checked')
	    {
	        isChecked=true;
	        openWindow(searchUrl+eval(tagsUrl[i].getAttribute('dir'))+'&kw='+escape(keyword)+'&title='+escape(tagsUrl[i].innerHTML));
	    }
	}
	if(!isChecked) alert('请选择搜索引擎！');
	return false;
}

function changeId(obj)
{
	try{
		var _obj=document.getElementById("s");
		if(_obj) _obj.id='';
		obj.id="s";
	}
	catch(e){}
}
function setSearchCheckbox(obj,checked)
{
    var objTags=obj.getElementsByTagName('label');
    for(var i=0;i<objTags.length;i++) objTags[i].className='';
	if(checked){
	    var objNode=getFirstChildNextSibling(obj);
	    overrideClick(objNode);
	}
	changeId(obj);
}

function initSearchCheckbox()
{
    var obj=document.getElementById('searchType');
	var objTags=obj.getElementsByTagName('ul')[0].getElementsByTagName('label');
	for(var i=0;i<objTags.length;i++)
	{     
		objTags[i].onclick=function(){
			this.className==''?this.className='checked':this.className='';
		}
		objTags[i].onfocus=function(){
		    this.blur();
		}
	}
}

function searchTab(id)
{
    var obj=document.getElementById(id),
        objFlag=document.getElementById('flag');
	var tits=obj.getElementsByTagName('h3')[0].getElementsByTagName('a'); 
	var cnts=obj.getElementsByTagName('ul')[0].getElementsByTagName('li');

	var len=tits.length; 
	var flag=1;//修改默认值
	for(var i=0;i<len;i++){
		tits[i].value = i;	
		tits[i].onclick=function(){			
			tits[flag].className='';			
			cnts[flag].style.display='none';
			setSearchCheckbox(cnts[flag]);
			flag=this.value;
			objFlag.value=flag+1;
			tits[flag].className='over';
			cnts[flag].style.display='inline';
			setSearchCheckbox(cnts[flag],'checked');
		};
		tits[i].onfocus=function(){this.blur();}
	}
	tits[flag].className='over';
	cnts[flag].style.display='inline';
	var objFlagNode=getFirstChildNextSibling(cnts[flag]);
	overrideClick(objFlagNode);
	objFlag.value=flag+1;
}

function selectEmail()
{
    var objMail=document.getElementById('mailType');
    var objEmail=document.getElementById('Email');
    var obj=document.getElementById('emailType');
    var tags=obj.getElementsByTagName('a');
    var len=tags.length;
    for(var i=0;i<len;i++){
        tags[i].onclick=function(){
            objMail.value=this.getAttribute('title');
            document.getElementById('iframeEmail').src='/include/email.html';
            objEmail.style.display='block';            
        }
    }
}
function emailLogin()
{
    var obj=document.getElementById('emailType');
    var objBtn=document.getElementById('btnEmail');
    if(obj.style.display=='block')
    {
        obj.style.display='none';
        objBtn.style.background='url(/images/emailBtn1.gif)';
    }
    else
    {
        obj.style.display='block';
        objBtn.style.background='url(/images/emailBtn.gif)';    
    }
}
function setHome(obj,URI){
	try{
			obj.style.behavior='url(#default#homepage)';obj.setHomePage(URI);
	}
	catch(e){
			if(window.netscape) {
					try {
							netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
					}
					catch (e) {
							alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
					}
					var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
					prefs.setCharPref('browser.startup.homepage',URI);
			 }
	}
	return false;
}